home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / programming / e / powerd0.06 / modules / dos / rdargs.m < prev    next >
Text File  |  1999-11-30  |  4KB  |  101 lines

  1. MODULE    'exec/nodes'
  2.  
  3. /**********************************************************************
  4.  *
  5.  * The CSource data structure defines the input source for "ReadItem()"
  6.  * as well as the ReadArgs call.  It is a publicly defined structure
  7.  * which may be used by applications which use code that follows the
  8.  * conventions defined for access.
  9.  *
  10.  * When passed to the dos.library functions, the value passed as
  11.  * struct *CSource is defined as follows:
  12.  *    if ( CSource == 0)    Use buffered IO "ReadChar()" as data source
  13.  *    else            Use CSource for input character stream
  14.  *
  15.  * The following two pseudo-code routines define how the CSource structure
  16.  * is used:
  17.  *
  18.  * long CS_ReadChar( struct CSource *CSource )
  19.  * {
  20.  *    if ( CSource == 0 )    return ReadChar();
  21.  *    if ( CSource->CurChr >= CSource->Length )    return ENDSTREAMCHAR;
  22.  *    return CSource->Buffer[ CSource->CurChr++ ];
  23.  * }
  24.  *
  25.  * BOOL CS_UnReadChar( struct CSource *CSource )
  26.  * {
  27.  *    if ( CSource == 0 )    return UnReadChar();
  28.  *    if ( CSource->CurChr <= 0 )    return FALSE;
  29.  *    CSource->CurChr--;
  30.  *    return TRUE;
  31.  * }
  32.  *
  33.  * To initialize a struct CSource, you set CSource->CS_Buffer to
  34.  * a string which is used as the data source, and set CS_Length to
  35.  * the number of characters in the string.  Normally CS_CurChr should
  36.  * be initialized to ZERO, or left as it was from prior use as
  37.  * a CSource.
  38.  *
  39.  **********************************************************************/
  40.  
  41. OBJECT CSource
  42.     Buffer:PTR TO UBYTE,
  43.     Length:LONG,
  44.     CurChr:LONG
  45.  
  46. /**********************************************************************
  47.  *
  48.  * The RDArgs data structure is the input parameter passed to the DOS
  49.  * ReadArgs() function call.
  50.  *
  51.  * The RDA_Source structure is a CSource as defined above;
  52.  * if RDA_Source.CS_Buffer is non-null, RDA_Source is used as the input
  53.  * character stream to parse, else the input comes from the buffered STDIN
  54.  * calls ReadChar/UnReadChar.
  55.  *
  56.  * RDA_DAList is a private address which is used internally to track
  57.  * allocations which are freed by FreeArgs().  This MUST be initialized
  58.  * to NULL prior to the first call to ReadArgs().
  59.  *
  60.  * The RDA_Buffer and RDA_BufSiz fields allow the application to supply
  61.  * a fixed-size buffer in which to store the parsed data.  This allows
  62.  * the application to pre-allocate a buffer rather than requiring buffer
  63.  * space to be allocated.  If either RDA_Buffer or RDA_BufSiz is NULL,
  64.  * the application has not supplied a buffer.
  65.  *
  66.  * RDA_ExtHelp is a text string which will be displayed instead of the
  67.  * template string, if the user is prompted for input.
  68.  *
  69.  * RDA_Flags bits control how ReadArgs() works.  The flag bits are
  70.  * defined below.  Defaults are initialized to ZERO.
  71.  *
  72.  **********************************************************************/
  73.  
  74. OBJECT RDArgs
  75.     Source:CSource,        /* Select input source */
  76.     DAList:LONG,            /* PRIVATE. */
  77.     Buffer:PTR TO UBYTE,    /* Optional string parsing space. */
  78.     BufSiz:LONG,            /* Size of RDA_Buffer (0..n) */
  79.     ExtHelp:PTR TO UBYTE,/* Optional extended help */
  80.     Flags:LONG                /* Flags for any required control */
  81.  
  82. #define RDAB_STDIN        0    /* Use "STDIN" rather than "COMMAND LINE" */
  83. #define RDAF_STDIN        1
  84. #define RDAB_NOALLOC        1    /* If set, do not allocate extra string space.*/
  85. #define RDAF_NOALLOC        2
  86. #define RDAB_NOPROMPT    2    /* Disable reprompting for string input. */
  87. #define RDAF_NOPROMPT    4
  88.  
  89. /**********************************************************************
  90.  * Maximum number of template keywords which can be in a template passed
  91.  * to ReadArgs(). IMPLEMENTOR NOTE - must be a multiple of 4.
  92.  **********************************************************************/
  93. #define MAX_TEMPLATE_ITEMS    100
  94.  
  95. /**********************************************************************
  96.  * Maximum number of MULTIARG items returned by ReadArgs(), before
  97.  * an ERROR_LINE_TOO_LONG.  These two limitations are due to stack
  98.  * usage.  Applications should allow "a lot" of stack to use ReadArgs().
  99.  **********************************************************************/
  100. #define MAX_MULTIARGS        128
  101.